import axios from 'axios'
import qs from 'qs'

let baseUrl = '/api'

export const axiosRequest = (type, path) => {
  let url = baseUrl + path
  return ({params = {}, success = () => {}, loding = false} = {}) => {
    if (type === 'get') {
      params = {
        params: params
      }
    }
    axios({
      method: type,
      url: url,
      data: qs.stringify(params)
    }).then((params) => {
      if (params) {
        let res = JSON.parse(params.request.response)
        success(res)
      }
    }).catch((error) => {
      console.log(error)
    })
  }
}
